package org.wattdepot.cli.processor;

import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import org.wattdepot.client.WattDepotClientException;

/**
 * Parses users input in the command line.
 * 
 * @author Anthony Xu & John Mack
 * 
 */
public class WattDepotCliProcessor {
  protected static final String SENSORDATA = "sensordata";

  /**
   * Tokenizes a string into a list of strings.
   * 
   * @param userInput user's input into command line
   * @return list of delimited strings
   */
  public List<String> tokenizeString(String userInput) {
    List<String> commands = new ArrayList<String>();
    StringTokenizer tokens = new StringTokenizer(userInput);
    while (tokens.hasMoreTokens()) {
      commands.add(tokens.nextToken());
    }
    return commands;
  }

  /**
   * parses command.
   * 
   * @param userCommandLineInput userCommandLineInput
   * @throws WattDepotClientException WattDepotClientException
   * @return string for use in hashmap
   */
  public String getCommand(List<String> userCommandLineInput) throws WattDepotClientException {
    String ret = "";
    if ("help".equals(userCommandLineInput.get(0))) {
      ret = "help";
    }
    
    else if ("sources".equals(userCommandLineInput.get(0))) {
        ret = "listSources";
      }
      else if ("source".equals(userCommandLineInput.get(0))
          && "summary".equals(userCommandLineInput.get(2))) {
        ret = "listSourceSummary";
      }
      else if ("sensordata".equals(userCommandLineInput.get(0))
          && "timestamp".equals(userCommandLineInput.get(2))) {
        ret = "listSensordataTimestamp";
      }
      else if ("dailysensordata".equals(userCommandLineInput.get(0))
          && "day".equals(userCommandLineInput.get(2))) {
        ret = "listSensordataDay";
      }     
      else if ("total".equals(userCommandLineInput.get(0))
          && "day".equals(userCommandLineInput.get(3))
          && "sampling-interval".equals(userCommandLineInput.get(5))) {
        ret = "listTotal";
      }
      else if ("powerstats".equals(userCommandLineInput.get(0))
          && "day".equals(userCommandLineInput.get(3))
          && "sampling-interval".equals(userCommandLineInput.get(5))
          && "statistic".equals(userCommandLineInput.get(7))) {
        ret = "listPowerGeneratedDay";
      }
      else if ("power".equals(userCommandLineInput.get(0)) 
          && "timestamp".equals(userCommandLineInput.get(2))) {
        ret = "listPowerGeneratedTimestamp";
      }
    
    else if ("chart".equals(userCommandLineInput.get(0))) {
      ret = "chartPower";
    }
    else if ("fueltypes".equals(userCommandLineInput.get(0))) {
      ret = "fueltypes";
    }
    else if ("totalpower".equals(userCommandLineInput.get(0))) {
      ret = "totalpower";
    }
    else if ("carboncontent".equals(userCommandLineInput.get(0))) {
      ret = "carboncontent";
    }
    return ret;
  }

}
